/**
 * 
 */
package vt.ruminote.fragment;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import vt.ruminote.AlbumActivity;
import vt.ruminote.MemoActivity;
import vt.ruminote.R;
import vt.ruminote.UnTrimActivity;
import vt.ruminote.util.ActivityUtil;
import android.annotation.SuppressLint;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;


/**
 * @author Jason
 *
 */
@SuppressLint("NewApi")
public class InfoListFragment extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        System.out.println("ListFragment-->OnCreateView");
        View view = (View)inflater.inflate(R.layout.main_listfraglayout, container, false);
        
        listInitial(view);
        return view;
        //return super.onCreateView(inflater, container, savedInstanceState);
    }

    /* (non-Javadoc)
     * @see android.app.Fragment#onActivityCreated(android.os.Bundle)
     */
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        System.out.println("ListFragment-->onActivityCreated");
        super.onActivityCreated(savedInstanceState);
    }
    
    private List<Map<String, Object>> getData() {
        
        List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();
        
        //below are four info bars
        for (int i = 0 ; i < 4 ; i++) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("itemTitle", "便签" + i);
            map.put("itemImage", R.drawable.ic_launcher);
            data.add(map);
        }
        
        return data;
    }
    
    private void listInitial(View parentView) {
        ListView listV = (ListView)parentView.findViewById(R.id.main_infolistView);
        SimpleAdapter listAdapter = new SimpleAdapter(listV.getContext(), getData(), R.layout.main_listviewlayout, 
                new String[] {"itemTitle", "itemImage"}, new int[] {R.id.main_ItemTitle, R.id.main_ItemImage});
        listV.setAdapter(listAdapter);
        listV.setOnItemClickListener(new listOnClickListener());
    }
    
    //判断哪个item被点击,启动响应的activity
    private class listOnClickListener implements AdapterView.OnItemClickListener{
        @Override
        public void onItemClick(AdapterView<?> arg0, View view, int position, long id) {
            // TODO Auto-generated method stub
            System.out.println("listOnClickListener-->onClick=" + position);
            switch(position) {
                case 0://便笺
                    ActivityUtil.goToActivity(getActivity(), MemoActivity.class);
                    break;
                case 1://专辑
                    ActivityUtil.goToActivity(getActivity(), AlbumActivity.class);
                    break;
                case 2://未整理
                    ActivityUtil.goToActivity(getActivity(), UnTrimActivity.class);
                    break;
            }
        }
        
    }
    
    
}
